package pub.tbc.api.service.initalize;

import lombok.extern.slf4j.Slf4j;
import pub.tbc.api.cache.CacheProvider;
import pub.tbc.api.cache.ServiceCache;
import pub.tbc.api.config.ConfigProvider;
import pub.tbc.api.config.PropertiesConfig;

/**
 * 使用本地配置文件初始化服务地址缓存，暂运行时变更检测
 *
 * @author tbc on 2017/3/22 16:26:10.
 */
@Slf4j
public class NativeConfigServiceCacheInit implements ServiceCacheInitializer {
    private ServiceCache serviceCache = CacheProvider.getServiceCache();

    @Override
    public void initServiceCache() {
        // 读取配置文件
        PropertiesConfig config = (PropertiesConfig) ConfigProvider.getPropertiesConfig("serviceRouter");
        config.keySet().forEach(k -> config.getList(k, ",").forEach(a -> serviceCache.addServiceAddress(k, a)));
    }
}
